package com.test.demo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jy on 2018/5/9.
 */

public class AdapterHaiKangMonitorList extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<ChannelInfo> channelInfos;

    public AdapterHaiKangMonitorList(Context context, ArrayList<ChannelInfo> channelInfos) {
        inflater = LayoutInflater.from(context);
        this.channelInfos = channelInfos;
    }

    @Override
    public int getCount() {
        return channelInfos != null ? channelInfos.size() : 0;
    }

    @Override
    public ChannelInfo getItem(int position) {
        return channelInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChannelInfo channelInfo = getItem(position);
        ViewHandler viewHandler;
        if (convertView == null) {
            viewHandler = new ViewHandler();
            convertView = inflater.inflate(R.layout.item_haikang_monitor_list, parent, false);
            viewHandler.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
//            viewHandler.tv_addr = (TextView) convertView.findViewById(R.id.tv_addr);
            convertView.setTag(viewHandler);
        } else {
            viewHandler = (ViewHandler) convertView.getTag();
        }

        viewHandler.tv_name.setText(channelInfo.channelName);
        return convertView;
    }

    private class ViewHandler {
        public TextView tv_name;
//        public TextView tv_addr;
    }
}
